package com.aiju.cash.widgit;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aiju.cash.R;

/**
 * @author: 佐为
 * @date: 2017-05-10 09:33
 * @version: V1.0
 * @Description: 优惠折扣
 */
public class DiscountView extends RelativeLayout {

    private int leftDrawable = R.mipmap.ic_jianjia;
    private int rightDrawable = R.mipmap.icon_setting_right;
    private String title, content;

    private TextView nameTextView, descTextView;
    private ImageView leftImageView;
    private ImageView rightImageView;

    public DiscountView(Context context) {
        super(context);
        initView();
    }

    public DiscountView(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.DiscountView);
        title = ta.getString(R.styleable.DiscountView_discount_top_text);
        content = ta.getString(R.styleable.DiscountView_discount_bottom_text);
        leftDrawable = ta.getResourceId(R.styleable.DiscountView_discount_left_drawable, leftDrawable);
        rightDrawable = ta.getResourceId(R.styleable.DiscountView_discount_right_drawable, rightDrawable);
        ta.recycle();
        initView();
    }

    private void initView() {
        LayoutInflater.from(getContext()).inflate(R.layout.layout_discount, this);
        nameTextView = (TextView) findViewById(R.id.tv_discount_name);
        descTextView = (TextView) findViewById(R.id.tv_discount_desc);
        leftImageView = (ImageView) findViewById(R.id.iv_discount_pic);
        rightImageView = (ImageView) findViewById(R.id.iv_discount_right);

        nameTextView.setText(title);
        descTextView.setText(content);
        leftImageView.setImageResource(leftDrawable);
        rightImageView.setImageResource(rightDrawable);
    }

    public void setTitle(String title) {
        nameTextView.setText(title);
    }

    public void setContent(String content) {
        descTextView.setText(content);
    }

    public void setLeftDrawable(int leftDrawable) {
        leftImageView.setImageResource(leftDrawable);
    }

    public void setRightDrawable(int rightDrawable) {
        rightImageView.setImageResource(rightDrawable);
    }

    public ImageView getRightImageView() {
        return rightImageView;
    }
}
